<div class="row">
	<div class="col-md-12">
		<form id="editForm" class="form-horizontal" action="${request.contextPath}/cms/ad/category/update" method="post" onsubmit="return false">
			<input type="hidden" id="id" name="id" value="${cmsAdCategory.id}">
			<div class="box-body">
				<div class="form-group">
					<label id="adCategorySiteIdLabel" for="adCategorySiteId" class="col-sm-2  control-label">所属站点</label>
					<div class="col-sm-10">
						<select class="form-control" id="adCategorySiteId"  name="siteId"  value="${cmsAdCategory.siteId}"  style="width: 100%;" placeholder="选择站点...">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="adCategoryNameLabel" for="adCategoryName" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="name" id="adCategoryName" value="${cmsAdCategory.name}" placeholder="输入名称...">
					</div>
					<label id="adCategoryCodeLabel" for="adCategoryCode" class="col-sm-2 control-label">编码</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="code" id="adCategoryCode" value="${cmsAdCategory.code}" placeholder="输入编码...">
					</div>
				</div>
				<div class="form-group">
					<label id="adCategoryDescriptionLabel" class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="description" id="adCategoryDescription" value="${cmsAdCategory.description}" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="adCategorySortOrderLabel" for="adCategorySortOrder" class="col-sm-2  control-label">排序</label>
					<div class="col-sm-2">
						<input  class="form-control" name="sortOrder" id="adCategorySortOrder" type="number"  value="${cmsAdCategory.sortOrder}" placeholder="请输入...">
					</div>
					<label id="adCategoryStatusLabel" for="adCategoryStatus" class="col-sm-2  control-label">状态</label>
					<div class="col-sm-2">
						<select class="form-control" id="adCategoryStatus"  name="status" value="${cmsAdCategory.status}"  style="width: 100%;">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="adCategoryRemarkLabel" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="remark" id="adCategoryRemark" value="${cmsAdCategory.remark}" placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" >
					<span class="error-icon"></span>
					<span id="error-msg" class="error-msg" ></span>
				</div>
             </div>
			<div class="box-footer">
				<div class="pull-right">
               		<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 更新</button>
               		<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>
				</div>
          	</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
	
	if ($form.length === 1 && $form.validate()) {
        $.ajax({
            type: 'post',
            url: form.action,
            dataType: "json",
            data: $form.serialize()
        }).done(function(result){
            if (result.success) {
                $("#lgModal").modal('hide');
                alertMsg(result.message,"success");
				dataGridReload();
            } else {
                $form.find(".error-msg").show();
                $form.find(".error-msg").html(result.message);
            }
        });
	}
}

$(function() {
    $("#adCategoryStatus").select2({
        data: StatusStore,
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    }).val('${cmsAdCategory.status}').trigger("change");

    //初始化时间选择器
    $('[name=startTime]').datetimepicker({
        format:"Y/m/d 00:00:00",      //格式化日期
        timepicker:true,    //开启时间选项
        yearStart:2000,     //设置最小年份
        yearEnd:2050,        //设置最大年份
        todayButton:false    //关闭选择今天按钮
    });

    //初始化时间选择器
    $('[name=endTime]').datetimepicker({
        format:"Y/m/d 23:59:59",      //格式化日期
        timepicker:true,    //开启时间选项
        yearStart:2000,     //设置最小年份
        yearEnd:2050,        //设置最大年份
        todayButton:false    //关闭选择今天按钮
    });

	$.ajax({
		type:"get",
		url:'/cms/site/list',
		dataType:'json'
	}).done(function(result){
		var o = [];
		var a = result;
		$.each(a, function() {
			if(this.id !== undefined && this.id !==''){
				o.push({'id':this.id,'text':this.name});
			}
		});
		$("#adCategorySiteId").select2({
			data:o,
			placeholder: "站点...",
			allowClear: true,
			language: "zh-CN",
			theme: "bootstrap"
		}).val('${cmsAdCategory.siteId}').trigger("change");
	});

	var $editForm = $("#editForm");
	$editForm.validate({
        rules: {
            name: {
                required: true
            },
			sortOrder: {
                required: true
            },
            status: {
                required: true
            }
        },
        messages: {
            name:{
                required:"名称不能为空！"
            },
			sortOrder:{
                required:"排序不能为空！"
            },
            status:{
                required:"状态不能为空！"
            }
        },
		submitHandler:ajaxSubmit,
		errorLabelContainer:".error-msg",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$editForm.find(".error-msg").html(errorList[0].message);
			}else{
				$editForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>